const crypt = require('crypto')


// let msg = 'hello, MD5摘要算法'
//
// let md5 = crypt.createHash('md5')
//
// md5_data = md5.update(msg).digest('hex')
// console.log('Md5后的数据:', md5_data)
//
// acffb8e4d57563e9168fd0376fa9da4c



function aesEncrypt(data, key, iv) {
    const cipher = crypt.createCipheriv('aes128', key, iv);
    var crypted = cipher.update(data, 'utf8', 'hex');
    crypted += cipher.final('hex');
    return crypted;
}

function aesDecrypt(encrypted, key, iv) {
    const decipher = crypt.createDecipheriv('aes128', key, iv);
    var decrypted = decipher.update(encrypted, 'hex', 'utf8');
    decrypted += decipher.final('utf8');
    return decrypted;
}

key = '1234567897891234'
iv = '1234567897891234'
data = "Hello, world!"
encrypt_data = aesEncrypt(data, key, iv)
console.log('加密后数据:', encrypt_data)

encrypt_data = 'f4d236a9e916d66cf064686f4eb67c03'
decrypt_data = aesDecrypt(encrypt_data, key, iv)
console.log('解密后数据:', decrypt_data)


